package br.edu.ufcg.dsc.services;

import java.util.List;

import javax.persistence.EntityTransaction;

import br.edu.ufcg.dsc.domain.configuration.Configuration;

public class ConfigurationService extends BaseService{

	public static void persist(Configuration c){
		EntityTransaction tx = entity.getTransaction();

		tx.begin();
		try{
			entity.merge(c);
			tx.commit();
		} catch (Exception e) {
			e.printStackTrace();
			tx.rollback();
		}
		
	}
	
	@SuppressWarnings("unchecked")
	public static Configuration getConfiguration(){
		List<Configuration> configuration = entity.createQuery("SELECT c FROM br.edu.ufcg.dsc.domain.configuration.Configuration c").getResultList();
		if (configuration.size() == 0) 
			return null;
		return configuration.get(0);
	}
}
